home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / Demos / AirHockey / cText.cls < prev    next >
Encoding:
Visual Basic class definition  |  2001-10-08  |  1.5 KB  |  57 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "cText"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15. 'Helper class to encapsulate text drawing
  16.  
  17. 'Here we will keep the font information and the calls to draw the text
  18. Private moD3DXFont As D3DXFont
  19.  
  20. Public Sub InitText(d3dx As D3DX8, dev As Direct3DDevice8, ByVal sFontName As String, lSize As Long, fBold As Boolean)
  21.     Dim oMyFont As IFont
  22.     
  23.     Set oMyFont = New StdFont
  24.     oMyFont.Name = "Times New Roman"
  25.     oMyFont.size = 8
  26.     oMyFont.Bold = True
  27.     
  28.     Set moD3DXFont = d3dx.CreateFont(dev, oMyFont.hFont)
  29.  
  30. End Sub
  31.  
  32. Public Sub BeginText()
  33.     moD3DXFont.Begin
  34. End Sub
  35.  
  36. Public Sub EndText()
  37.     moD3DXFont.End
  38. End Sub
  39.  
  40. Public Sub DrawText(ByVal sText As String, X As Long, Y As Long, lColor As Long)
  41.     Dim rcText As RECT
  42.     
  43.     'X and Y are in screen coords
  44.     rcText.Left = X
  45.     rcText.Top = Y
  46.     'actually draw the text now, telling d3dx to build the rectangle based on the text and the x,y coord
  47.     moD3DXFont.DrawTextW sText, -1, rcText, 0, lColor
  48. End Sub
  49.  
  50. Private Sub Class_Initialize()
  51.     Set moD3DXFont = Nothing
  52. End Sub
  53.  
  54. Private Sub Class_Terminate()
  55.     Set moD3DXFont = Nothing
  56. End Sub
  57.